package com.sia.springcloud.protocol.config;

import com.sia.springcloud.protocol.job.CollectJob;
import com.sia.springcloud.model.Device;
import com.sia.springcloud.model.Point;
import lombok.extern.slf4j.Slf4j;
import org.quartz.JobBuilder;
import org.quartz.JobDataMap;
import org.quartz.JobDetail;

/**
 * @Author: Sirius
 * @Date: 2021/12/29 19:37
 * @Description: JobDetail的配置类
 **/
@Slf4j
public class JobDetailConfig {

    /**
     * 根据一个Device对象、一个Point对象配置一个数采任务的JobDetail
     *
     * @param point
     * @param device
     * @return 一个JobDetail
     */
    public static JobDetail newJobDetail(Device device, Point point, String topicName) {
        log.info("JobDetail：Job初始化");
        JobDetail jobDetail = JobBuilder.newJob(CollectJob.class)
                .withIdentity(String.valueOf(point.getId()))
                .storeDurably()
                .build();


        log.info("JobDetail：JobDataMap初始化");
        JobDataMap jobDataMap = jobDetail.getJobDataMap();
        jobDataMap.put("device", device);
        jobDataMap.put("point", point);
        jobDataMap.put("topicName", topicName);

        return jobDetail;
    }
}
